import createReducer from 'utils/createReducer';
import {
  GET_USER_INFO_SUCCESS,
  LOAD_INIT_DATA_SUCCESS,
  LOAD_INIT_DATA_FAIL,
} from './actions';

/* createReducer
export default function (handlers) {
  const { CONSTRUCT: construct } = handlers;
  const initialState = construct ? construct() : {};

  return function reducer(state = initialState, action) {
    if (Object.hasOwnProperty.call(handlers, action.type)) {
      return handlers[action.type](state, action);
    }
    return state;
  };
}
*/
export default createReducer({
  CONSTRUCT: () => ({
    userInfo: {},
  }),

  [GET_USER_INFO_SUCCESS]: (state, action) => {
    const { userInfo, payload } = action;
    console.log('GET_USER_INFO_SUCCESS', action, userInfo, payload);
    return ({
      ...state,
      userInfo,
    });
  },

  [LOAD_INIT_DATA_SUCCESS]: (state, action) => {
    console.log('LOAD_INIT_DATA_SUCCESS', action);
    return ({
      ...state,
    });
  },

  [LOAD_INIT_DATA_FAIL]: (state, action) => {
    console.log('LOAD_INIT_DATA_FAIL', action);
    return ({
      ...state,
    });
  },
});
